package com.ruoyi.system.controller;

import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.system.domain.Area;
import com.ruoyi.system.service.AreaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @packageName: com.ruoyi.system.controller
 * @user: andyliu
 * @date: 2023/2/18 14:32
 * @email 115176513@qq.com
 * @description: TODO
 */
@RestController
@RequestMapping("/area")
public class AreaController extends BaseController {
    @Autowired
    private AreaService service;

    @GetMapping("/list")
    @RequiresPermissions("area:list")
    public TableDataInfo list(Area area){
        startPage();
        List<Area> areas = service.queryAreas(area);
        return getDataTable(areas);
    }

    @PostMapping("/save")
    @Log(title = "区域管理",businessType = BusinessType.INSERT)
    public AjaxResult save(@RequestBody Area area){
        boolean b = service.saveOrUpdate(area);
        return AjaxResult.success(b);
    }

    @DeleteMapping("/delete/{id}")
    @Log(title="区域管理",businessType = BusinessType.DELETE)
    public AjaxResult delete(@PathVariable Integer id){
        boolean b = service.removeById(id);
        return AjaxResult.success(b);
    }
    @DeleteMapping("/deletes/{ids}")
    @Log(title="区域管理",businessType = BusinessType.DELETE)
    public AjaxResult deletes(@PathVariable Integer[] ids){
        boolean b = service.removeByIds(ids);
        return AjaxResult.success(b);
    }
    @GetMapping("/info/{id}")
    public AjaxResult info(@PathVariable Integer id){
        Area area = service.queryById(id);
        return AjaxResult.success(area);
    }


}
